package com.rst.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.rst.model.BookCategory;

@Repository
@Transactional
public class BookCategoryDAO {

	@Autowired
	private SessionFactory sessionFactory;

	public void saveBookCategory(BookCategory bookCategory) {
		sessionFactory.getCurrentSession().saveOrUpdate(bookCategory);		
	}

	public BookCategory getBookCategoryById(Long bookCategoryId) {
	    Session session = sessionFactory.getCurrentSession();
	    BookCategory bookCategory = (BookCategory)session.get(BookCategory.class, bookCategoryId);
		return bookCategory;
	}

	@SuppressWarnings("unchecked")
	public List<BookCategory> getBookCategoryList() {
		Session session = sessionFactory.getCurrentSession();
	    String str = "FROM BookCategory bc WHERE bc.status = :status  ";
	    	
	    Query query = session.createQuery(str);
	    query.setParameter("status",  BookCategory.ACTIVE);
		return query.list();
	}

	public void updateBookCategory(BookCategory bookCategory) {
		// TODO Auto-generated method stub
		
	}
}




